//
//  ChooseTeamController.m
//  soccer
//
//  Created by 上官千城 on 15/9/10.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "OChooseTeamController.h"
#define item  WIDTH/4
@interface OChooseTeamController ()

@end

@implementation OChooseTeamController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"球队偏好设置";
    //选择的队伍
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 200) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
    //选择联赛
    self.tableViewZone = [[UITableView alloc]initWithFrame:CGRectMake(0, self.tableView.frame.size.height, item, HEIGHT - self.tableView.frame.size.height -110) style:UITableViewStylePlain];
    self.tableViewZone.delegate = self;
    self.tableViewZone.dataSource = self;
//    self.tableViewZone.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableViewZone];
    //选择球队
    self.tableViewTeam = [[UITableView alloc]initWithFrame:CGRectMake(self.tableViewZone.frame.origin.x + self.tableViewZone.frame.size.width, self.tableViewZone.frame.origin.y, WIDTH - self.tableViewZone.frame.size.width, self.tableViewZone.frame.size.height ) style:UITableViewStylePlain];
//    self.tableViewTeam.backgroundColor = [UIColor orangeColor];
    self.tableViewTeam.delegate = self;
    self.tableViewTeam.dataSource = self;
    self.tableViewTeam.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableViewTeam];
    //适应View
    UIView *av = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableViewTeam.frame.size.width, 10)];
    self.tableViewTeam.tableFooterView = av;
//    self.tableViewZone.tableFooterView = av;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == self.tableViewZone) {
        UITableViewCell *cell1 = [[UITableViewCell alloc]init];
        //  联赛图标
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, item, item)];
        for (int i = 0; i < 5; i++) {
            if (indexPath.row == i ) {
                NSString *str = [NSString stringWithFormat:@"team%d",i+1];
                image.image = [UIImage imageNamed:str];
            }
            [cell1 addSubview:image];
        }
        return cell1;
    }
    
    if (tableView == self.tableView) {
        //最喜欢的队伍
        UITableViewCell *cell2 = [[UITableViewCell alloc]init];

        if (indexPath.row == 0) {
            self.bestTeam = [UIButton buttonWithType:UIButtonTypeCustom];
            self.bestTeam.frame = CGRectMake(10, 10, 60, 60);
            [self.bestTeam setImage:[UIImage imageNamed:@"未标题-1_17@2x"] forState:UIControlStateNormal];
        
            [self.bestTeam addTarget:self action:@selector(deleteTeam) forControlEvents:UIControlEventTouchUpInside];
            [cell2 addSubview:self.bestTeam];
    // "-"
            UILabel *sub = [[UILabel alloc]initWithFrame:CGRectMake(self.bestTeam.frame.size.width-8, self.bestTeam.frame.origin.y-10, 10, 10)];
            sub.text = @"-";
            sub.textAlignment = NSTextAlignmentCenter;
            sub.backgroundColor = [UIColor greenColor];
            [self.bestTeam addSubview:sub];
    }
        //其他喜欢的队伍
        if (indexPath.row == 1) {
    
    }
            cell2.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell2;
    }
    //选择队伍
    if (tableView == self.tableViewTeam) {
        UITableViewCell *cell3 = [[UITableViewCell alloc]init];
        int k = 1;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
                imgButton.frame = CGRectMake(5 + item * j , 10 + item * i, item , item );
                NSString *str = [NSString stringWithFormat:@"4%.2d",k];
                [imgButton setImage:[UIImage imageNamed:str] forState:UIControlStateNormal];
                [cell3 addSubview:imgButton];
                k++;
            }
        }
        
        cell3.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell3;
    }
    return nil;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.tableViewZone) {
        return 5;
    }
    if (tableView == self.tableView) {
        return 2;
    }
    return 1;
    
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableView) {
        return 80;
    }
    if (tableView == self.tableViewZone) {
        return  item;
    }
    return HEIGHT - self.tableView.frame.size.height;
}
//点击触发方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableViewZone) {

    }
}
    
    
    
    
    
    
    
-(void)deleteTeam
{
    NSLog(@"删除");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
